﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Windows.Forms;

namespace commonV2.forms
{
    public partial class checkLicense : forms.baseLicense 
    {
        public checkLicense()
        {
            InitializeComponent();
            this.allowToChangeHwInfo = false;
        }
        public string myProdVendor = "", myProductCode = "";

        public override void SetLanguage()
        {
            base.SetLanguage();
            this.Text = language.GetString("license");
            this.viewLicenceBtn.Text = language.GetString("view");
            this.exportBtn.Text = language.GetString("export");
        }

        protected override bool BeforeAcceptProcess()
        {
            this.ShowMessage("");
            if (this.myFormStatus.isCloseClick) return true;
            if (!LicenseLibs.ChecLicence(this.myProdVendor, this.myProductCode, this.myLicense))
            {
                SysLibs.ShowErrorMessage(language.GetString("invalidLicense"));
                return false;
            }
            LicenseLibs.SaveLicence(this.myLicense,this.myLicenceFile);
            this.ShowMessage(language.GetString("dataWereSaved"));
            return true;
        }
        private void viewLicenceBtn_Click(object sender, EventArgs e)
        {
            LicenseLibs.myLicenseItem lic = this.GetLicence();
            if (lic == null)
            {
                SysLibs.ShowErrorMessage(language.GetString("invalidLicense"));
                return;
            }    
            this.myLicense  =  lic;
        }

        private void exportBtn_Click(object sender, EventArgs e)
        {
            this.ShowMessage("");
            LicenseLibs.myLicenseItem lic = new LicenseLibs.myLicenseItem();
            lic = this.myLicense;
            lic.hwInfo = HardwareLibs.GetHardwareInfo();
            string fname = FindSaveFile();
            if (fname == null) return;
            this.SaveLicence(lic, fname);
            SysLibs.ShowErrorMessage(String.Format(language.GetString("dataSavedTo"), fname));
        }
    }
}
